//
//  BibleViewController.m
//  GC_OC
//
//  Created by 曾 on 2022/1/16.
//

#import "BibleViewController.h"
#import "BibleTitleView.h"
@interface BibleViewController ()
@property (nonatomic, strong)ObjectAFNetWorking* objectAFN;
@property (nonatomic, strong)NSDictionary* dic;
@property (nonatomic, strong)BibleTitleView* titleView;
@property (nonatomic, assign) BOOL notFirst;
@end

@implementation BibleViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.notFirst = true;
    
    self.view.backgroundColor=RBG(250,250,250);
    self.objectAFN = [[ObjectAFNetWorking alloc]init];
    [self getData];
}
- (void)viewDidAppear:(BOOL)animated
{
    [super viewDidAppear:animated];
    
    if (self.notFirst && !self.dic) {
        [self getData];
    }
    
    self.titleView.needScrollCrrentSong = true;
}

- (void)viewWillDisappear:(BOOL)animated {
    [super viewWillDisappear:animated];
    if ([SUPlayerManager manager].isPlaying) {
        [[SUPlayerManager manager] pausePlay];
    }
}

-(void)getData
{
    @weakify(self)
    [FKCacheTool getIndexData:self.idString complete:^(id data) {
        @strongify(self)
        self.dic = data;
        [self upDateView];
    }];
}

- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
    [self.navigationController setNavigationBarHidden:YES animated:YES];
    
    if ([SUPlayerManager manager].currentSong) {
        CGFloat height = 0;
        if (@available(iOS 13.0, *)) {
            NSSet *set = [UIApplication sharedApplication].connectedScenes;
            UIWindowScene *windowScene = [set anyObject];
            UIWindow *window = windowScene.windows.firstObject;
            height = window.safeAreaInsets.bottom;
        } else if (@available(iOS 11.0, *)) {
            UIWindow *window = [UIApplication sharedApplication].windows.firstObject;
            height = window.safeAreaInsets.bottom;
        }
        height += 49;

        [[SUPlayerManager manager].bottomView mas_updateConstraints:^(MASConstraintMaker *make) {
            make.left.right.equalTo([UIApplication sharedApplication].keyWindow);
            make.bottom.equalTo([UIApplication sharedApplication].keyWindow).offset(-height);
            make.height.mas_equalTo(60);
        }];
        
    }
}

-(void)upDateView
{
    [self.view addSubview:self.titleView];
}

- (BibleTitleView*)titleView
{
    if(!_titleView)
    {
        _titleView=[[BibleTitleView alloc]initWithFrame:CGRectMake(0,StatusBarHeight,SCREEN_WIDTH,SCREEN_HEIGHT-GCtabbarHeight-StatusBarHeight) andDic:self.dic idString:self.idString];

    }
    return _titleView;
}

- (void)setIdString:(NSString *)idString {
    _idString = idString;
    _titleView.idString = self.idString;
}

@end
